var mongomq = require('mongomq');
var constants = require('./constants.js');

console.log('creating mongo mq...');
var queue = new mongomq.MongoMQ({
	server: constants.queue.SERVER,
	autoStart: false
});

// set server forcely
queue.mongoConnection.server.host = constants.queue.SERVER;
console.log('mongoConnection: ' + JSON.stringify(queue.mongoConnection));

queue.start(function() {
	console.log('Queue listening started.');
	console.log('active: ' + queue.mongoConnection.active);

	queue.on('mail', function(err, data, next) {
		console.log('notification: ' + JSON.stringify(data));
		next();
	});
});